package com.zillion.web.controller.employ;

import com.zillion.common.core.controller.BaseController;
import com.zillion.common.core.domain.AjaxResult;
import com.zillion.common.utils.poi.ExcelUtil;
import com.zillion.employee.domain.UnitApply;
import com.zillion.employee.domain.UnitPerson;
import com.zillion.employee.service.IUnitApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 从业人员个人上报处理
 *
 * @author zillion
 */
@RestController
@RequestMapping("/employee/unitApply")
public class UnitApplyController extends BaseController {

    @Autowired
    private IUnitApplyService unitApplyService;

    /**
     * 新增个人申报信息
     */
    @PostMapping
    public AjaxResult add(@RequestBody UnitApply unitApplyInfo) {
        return toAjax(unitApplyService.insertUnitApply(unitApplyInfo));
    }

    /**
     * 导出模板
     * @param response 响应对象
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<UnitPerson> util = new ExcelUtil<UnitPerson>(UnitPerson.class);
        util.importTemplateExcel(response, "企业人员信息");
    }

    /**
     * 通过excel导入数据
     * @param file 文件
     * @return 结果
     * @throws Exception 错误
     */
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<UnitPerson> util = new ExcelUtil<UnitPerson>(UnitPerson.class);
        List<UnitPerson> unitPersonList = util.importExcel(file.getInputStream());
//        String message = unitApplyService.importUnitPerson(unitPersonList);
        return success();
    }
}
